# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=hidapi
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.0
pkgrel=1
pkgdesc="Library for communicating with USB and Bluetooth HID devices (mingw-w64)"
arch=('any')
url="https://github.com/libusb/hidapi"
license=("BSD" "GPLv3")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("https://github.com/libusb/hidapi/archive/${_realname}-${pkgver}.tar.gz")
sha256sums=('630ee1834bdd5c5761ab079fd04f463a89585df8fcae51a7bfe4229b1e02a652')

prepare() {
  cd ${srcdir}/${_realname}-${_realname}-${pkgver}
  autoreconf -vif
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}-${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --disable-testgui
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  install -Dm644 ${srcdir}/${_realname}-${_realname}-${pkgver}/LICENSE{-bsd,-gpl3,-orig,}.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/
}
